import {clientRegister, clientUpdate} from './service';
import {message} from "antd";
import {history} from "umi";

const Model = {
  namespace: 'minerAdd',
  state: {
    Msg: undefined,
  },
  effects: {
    *submit({ payload }, { call, put }) {
      const response = yield call(clientRegister, payload);
      yield put({
        type: 'registerHandle',
        payload: response,
      });
    },
    *update({ payload }, { call, put }) {
      const response = yield call(clientUpdate, payload);
      yield put({
        type: 'updateHandle',
        payload: response,
      });
    },
  },
  reducers: {
    registerHandle(state, { payload }) {
      console.log(state)
      console.log(payload)
      if (payload.Code === 0) {
        message.success('注册成功！');
        history.push({
          pathname: '/MinerList', // state: {
          //   account,
          // },
        });
      } else {
        message.error(payload.Msg);
      }
      return { ...payload};
    },
    updateHandle(state, { payload }) {
      console.log(state)
      console.log(payload)
      if (payload.Code === 0) {
        message.success('更新成功！');
        history.push({
          pathname: '/MinerList', // state: {
          //   account,
          // },
        });
      } else {
        message.error(payload.Msg);
      }
      return { ...payload};
    },
  },
};
export default Model;
